package top.yuzt.animalserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.yuzt.animalserver.entity.Animal;
import top.yuzt.animalserver.entity.Medical;
import top.yuzt.animalserver.service.impl.AnimalServiceImpl;
import top.yuzt.animalserver.service.impl.MedicalServiceImpl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/count")
public class CountController {

    @Autowired
    private MedicalServiceImpl medicalService;

    @Autowired
    private AnimalServiceImpl animalService;

    @GetMapping("/medical")
    public Integer[] getcoutmedical(){
        Integer tmp[] = new Integer[3];
        Arrays.fill(tmp, 0);
        for (Medical medical: medicalService.list()){
            if(medical.getApplicationStatus().equals("待处理")){
                tmp[0]++;
            }
            if(medical.getApplicationStatus().equals("处理中")){
                tmp[1]++;
            }
            if(medical.getApplicationStatus().equals("已结束")){
                tmp[2]++;
            }
        }
        return tmp;
    }

    @GetMapping("/anmimaltype")
    public Integer getAnimaltype(){
        List<String> strings = new ArrayList<>();
        for (Animal animal : animalService.list()){
            if(!strings.contains(animal.getType())){
                strings.add(animal.getType());
            }
        }
        return strings.size();
    }

    @GetMapping("/anmimal")
    public Integer getAnimal(){
        return animalService.list().size();
    }

    @GetMapping("/medicalfinsh")
    public Integer getMedicalFins(){
        return getcoutmedical()[2];
    }


}
